package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.ContractMapper;
import com.cn.crmsystem.pojo.Contract;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
@Service
public class ContractServiceImpl implements ContractService {
    @Autowired
    private ContractMapper contractMapper;

    @Override
    public ResultJson selectAll(Contract contract) {
        List selectAllcontract = contractMapper.selectAllContract(contract);
        ResultJson resultJson = new ResultJson();
        if (selectAllcontract != null) {
            resultJson.getSuccess("成功",selectAllcontract);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public ResultJson selectContract(Integer id) {
        Contract selectcontract = contractMapper.selectContract(id);
        ResultJson resultJson = new ResultJson();
        if (selectcontract != null) {

            resultJson.getSuccess("成功", selectcontract);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }


    @Override
    public ResultJson addContract(Contract contract,Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("contract",contract);
        map.put("login",login);

        int addcontract = contractMapper.addContract(map);
        ResultJson resultJson = new ResultJson();
        if (addcontract > 0) {
            resultJson.getSuccess("成功", addcontract);
        } else {
            resultJson.getSuccess("失败", "202");
        }

        return resultJson;
    }

    @Override
    public ResultJson updateContract(Contract contract
    ) {

        int updatecontract = contractMapper.updatecontract(contract);
        ResultJson resultJson = new ResultJson();
        if (updatecontract > 0) {
            resultJson.getSuccess("成功", updatecontract);
        } else {
            resultJson.getSuccess("失败", "202");
        }
        return resultJson;
    }

    /**
     * 根据ID删除
     *
     * @param id
     * @return
     */
    @Override
    public ResultJson deleteByIdContract(Integer id) {
        int deleteByIdcontract = contractMapper.deleteByIdcontract(id);
        ResultJson resultJson = new ResultJson();
        if (deleteByIdcontract > 0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");
        }
        return resultJson;
    }


}
